#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
typedef double db;
inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') { if(ch=='-')f=-1; ch=getchar(); }
	while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+ch-'0'; ch=getchar(); }
	return x*f;
}
const int MAXN=5e5+10;
int n,m,x[MAXN],l[MAXN],r[MAXN];
int main()
{
	n=read();m=read();
	x[0]=l[0]=r[0]=0;
	for(int i=1;i<=n;++i)
	{
		x[i]=read();l[i]=read();r[i]=read();
		l[i]=max(l[i]+1,l[i-1]-(x[i]-x[i-1]));
		r[i]=min(r[i]-1,r[i-1]+(x[i]-x[i-1]));
		if((l[i]+x[i])&1)++l[i];
		if((r[i]+x[i])&1)--r[i];
		if(l[i]>r[i])
		{
			puts("NIE");
			return 0;
		}
	}
	printf("%d\n",(l[n]+x[n])>>1);
	return 0;
}
